<?php include '../public/header.php' ?>
<?php include '../public/header_index.php' ?>
<body class="laytp-container">
<div id="opt_nav">
</div>

<div class="layui-card" id="search-form">
    <div class="layui-card-body">
        <form class="layui-form" id="TableSearchFormId" lay-filter="TableSearchForm" onkeydown="keyTableSearch('TableSearchForm', 'datalist')">
            <div class="layui-form-item">
                <div class="layui-row">
                    <div class="layui-col-md3">
                        <label class="layui-form-label">申请时间</label>
                        <div class="layui-input-block">
                            <input type="text" readonly name="created_at" id="created_at" placeholder="请输入" autocomplete="off" class="layui-input bdate_sea_range_ymd">
                        </div>
                    </div>
                    <div class="layui-col-md3">
                        <label class="layui-form-label">流程单号</label>
                        <div class="layui-input-block">
                            <input type="text" name="sericnum" placeholder="请输入" class="layui-input" autocomplete="off">
                        </div>
                    </div>
                    <div class="layui-col-md3">
                        <label class="layui-form-label">审核状态：</label>
                        <div class="layui-input-block">
                            <select id="status" name="status" lay-filter="status">
                                <option value="">请选择</option>
                                <option value="1">流程（审批通过）</option>
                                <option value="0">流程（审批中）</option>
                            </select>
                        </div>
                    </div>
                    <div class="layui-col-md3 search_hide none">
                        <label class="layui-form-label">工程名称</label>
                        <div class="layui-input-block">
                            <input type="text" name="engin_name" placeholder="请输入" class="layui-input" autocomplete="off">
                        </div>
                    </div>

                    <div class="layui-col-md3 search_hide none">
                        <label class="layui-form-label">款项类型</label>
                        <div class="layui-input-block">
                            <div id="zhikuanlei" class="xmselect_div">
                                <div class="xmselect_title">请选择</div>
                            </div>
                        </div>
                    </div>
                    <div class="layui-col-md3 search_hide none">
                        <label class="layui-form-label">付款对象</label>
                        <div class="layui-input-block">
                            <input type="text" name="fuer" placeholder="请输入" class="layui-input" autocomplete="off">
                        </div>
                    </div>
                    <div class="layui-col-md3 search_hide none">
                        <label class="layui-form-label">支付方式</label>
                        <div class="layui-input-block">
                            <div id="incdaotype" class="xmselect_div">
                                <div class="xmselect_title">请选择</div>
                            </div>
                        </div>
                    </div>
                    <div class="layui-col-md3 search_hide none">
                        <label class="layui-form-label">是否返款：</label>
                        <div class="layui-input-block">
                            <select id="isfan" name="isfan" lay-filter="isfan">
                                <option value="">请选择</option>
                                <option value="是">是</option>
                                <option value="否">否</option>
                            </select>
                        </div>
                    </div>
                    <div class="layui-col-md3 search_hide none">
                        <label class="layui-form-label">工程编号</label>
                        <div class="layui-input-block">
                            <input type="text" name="engin_number" placeholder="请输入" class="layui-input" autocomplete="off">
                        </div>
                    </div>
                    <div class="layui-col-md3 search_hide none">
                        <label class="layui-form-label">工程状态：</label>
                        <div class="layui-input-block">
                            <select id="engin_state" name="engin_state" lay-filter="engin_state">
                                <option value="">请选择</option>
                            </select>
                        </div>
                    </div>
                    <div class="layui-col-md3 search_hide none">
                        <label class="layui-form-label">工程负责人</label>
                        <div class="layui-input-block">
                            <input type="text" name="engin_gofuer" placeholder="请输入" class="layui-input" autocomplete="off">
                        </div>
                    </div>
                    <div class="layui-col-md3 search_hide none">
                        <label class="layui-form-label">申请人</label>
                        <div class="layui-input-block">
                            <input type="text" name="flowuser" placeholder="请输入" class="layui-input" autocomplete="off">
                        </div>
                    </div>
<!--                    <div class="layui-col-md3 search_hide none">-->
<!--                        <label class="layui-form-label">票据状态：</label>-->
<!--                        <div class="layui-input-block">-->
<!--                            <select id="statename" name="statename" lay-filter="statename">-->
<!--                                <option value="">请选择</option>-->
<!--                                <option value="已收票">已收票</option>-->
<!--                                <option value="部分收票">部分收票</option>-->
<!--                                <option value="未收票">未收票</option>-->
<!--                            </select>-->
<!--                        </div>-->
<!--                    </div>-->
                    <div class="layui-col-md3">
                        <div class="layui-form-item search-div">
                            <div class="layui-form-item layui-inline">
                                <button class="laytp-btn laytp-btn-md laytp-btn-primary" id="TableSearchButton" type="button"><i class="layui-icon layui-icon-search"></i>查询</button>
                                <button class="layui-btn layui-btn-primary" onclick="listTableReset()" id="TableSearchReset" type="reset" ><i class="layui-icon layui-icon-refresh"></i>重置</button>
                                <div id="search_open" onclick="toggle_search()">
                                    <i class="layui-icon layui-icon-down"></i>展开
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </form>
    </div>
</div>

<div class="layui-card" id="table-card">
    <div class="layui-card-body">
        <div class="layui-row">
            <div class="layui-col-md12" id="table_list">
                <div class="layui-card-body">
                    <table id="datalist" lay-filter="datalist"></table>
                </div>
            </div>
        </div>
    </div>
</div>

<script type="text/html" id="test-dropdown-toolbar-barDemo">
    <div class="tab-list-authbut">
        <a href="javascript:;" class="bar_opt" onclick="auth_but_func_show('查看','{{d.LAY_TABLE_INDEX}}')">查看</a>
    </div>
</script>
<script type="text/html" id="toolbarDemo">
    <div class = "layui-btn-container">
        <button class="layui-btn layui-btn-primary outbut" onclick="auth_but_func_fan('返款登记')">返款登记</button>
    </div>
</script>
<script>
    var deafault_created_at = getRecentThreeMonthsDateRange();
    $("#created_at").val(deafault_created_at);

    var param_listid = getQueryVariable('listid') || 0;
    if(param_listid > 0){
        deafault_created_at = '';
        $("#created_at").val(deafault_created_at);
    }


    var param_enginid = getQueryVariable('enginid') || 0;
    var param_dealtype = getQueryVariable('dealtype') || 0;
    var param_zhikuanlei = getQueryVariable('zhikuanlei') || 0;
    var param_qutype = getQueryVariable('qutype') || 0;
    var param_fuer = decodeURI(getQueryVariable('fuer') || '') || '';

    layui.use(["laytp",'laypage','table','dropdown','form','soulTable'], function () {
        var laypage = layui.laypage, table = layui.table, dropdown = layui.dropdown, form = layui.form, soulTable = layui.soulTable;


        $('#TableSearchReset').click(function () {
            $('.xmselect_div>xm-select').find('.xm-label-block').css('display','none');
            $('.xmselect_div').append('<div class="xmselect_title">请选择</div>');
            searchTableFunc(form, table)
        });

        setSouTableExport('付款明细');
        var mytable = table.render({
            elem: "#datalist",id: "datalist"
            ,url: facade.url(ask_hou_gongzhi_detail),where: {enginid:param_enginid,dealtype:param_dealtype,listid:param_listid
                ,zhikuanlei:param_zhikuanlei,qutype:param_qutype,fuer:param_fuer,created_at:deafault_created_at}, page: true, height: 'full-140'
            ,soulSort: TabInit.soulSort,method: TabInit.method, toolbar: TabInit.toolbar, overflow: TabInit.overflow
            ,defaultToolbar: TabInit.defaultToolbar,filter: TabInit.filter
            ,request: TabInit.request,response: TabInit.response,contextmenu:get_table_contextmenu(soulTable)
            ,text: TabInit.text,totalRow: true
            ,parseData: function (res) {
                var  sea_zhikuanlei = res.data.is_zhikuanlei;
                if(!sea_zhikuanlei){
                    if(param_zhikuanlei){
                        sea_zhikuanlei = param_zhikuanlei
                    }
                }
                xmselect_dan('zhikuanlei', res.data.zhikuanlei, sea_zhikuanlei, function (res) {
                    setTimeout(function () {
                        searchTableFunc(form, table);
                    },100)
                })

                xmselect_dan('incdaotype', res.data.incdaotype, res.data.is_incdaotype, function (res) {
                    setTimeout(function () {
                        searchTableFunc(form, table);
                    },100)
                })


                var engin_state_str = '<option value="">请选择</option>';
                var engin_state = res.data.engin_state;
                for (var key in engin_state){
                    if(res.data.is_engin_state == key){
                        engin_state_str += '<option value="'+key+'" selected>'+engin_state[key]+'</option>';
                    }else {
                        engin_state_str += '<option value="'+key+'">'+engin_state[key]+'</option>';
                    }

                }
                $("#engin_state").html(engin_state_str);

                render_from();
                return {
                    "code": res.code,
                    "msg": res.message,
                    "count": res.data.data.total,
                    "data": res.data.data.data
                };
            }
            , cols: [[
                {type: "checkbox", fixed: 'left'}
                ,{type:'numbers',title:'序号',totalRowText: '合计',fixed:'left'}
                ,{field:'sericnum',title:'流程单号',templet: function(d){
                        return '<span class="colorlan" onclick="openPage(\'../hou_gongzhi/show.php?id='+d.id+'\');">'+d.sericnum+'</span>';
                    }}
                ,list_bill_cols_str
                ,{field: 'fuer', title: '付款对象'}
                ,{field:'isfan',title:'是否返款',templet: function(d){
                    if(d.isfan == '是'){
                        return '<span class="colorlv">'+d.isfan+'</span>';
                    }else if(d.isfan == '否'){
                        return '<span class="colorhuang">'+d.isfan+'</span>';
                    }else{
                        return d.isfan;
                    }
                }}
                ,{field: 'fanshuo', title: '返款说明',hide:true}
                ,{field:'cainame',title:'本次支付关联采购合同',hide:true,templet: function(d){
                    if(d.caiid > 0){
                        return '<span class="colorlan" onclick="openPage(\'../contract_cai/show.php?id='+d.caiid+'\')">'+d.cainame+'</span>';
                    }else{
                        return '';
                    }
                }}
                ,{field: 'moneyshuo', title: '资金渠道及金额'}
                ,{field: 'incdaotype_name', title: '支付方式'}
                ,{field: 'bankzhang', title: '账户名称'}
                ,{field: 'banknum', title: '账号'}
                ,{field: 'bankname', title: '开户行'}
                ,{field: 'zhikuanlei_name', title: '款项类型'}
                ,{field:'listmoney',title:'本次付款金额(元)A',totalRow: true,templet: function(d){
                        return parseFormatNum(d.listmoney);
                    }}
                ,{field: 'listexplain', title: '款项说明'}
                ,{field:'statename',title:'票据状态',templet: function(d){
                    if(d.statename == '已收票'){
                        return '<span class="colorlv">'+d.statename+'</span>';
                    }else if(d.statename == '部分收票'){
                        return '<span class="colorhuang">'+d.statename+'</span>';
                    }else if(d.statename == '未收票'){
                        return '<span class="colorhong">'+d.statename+'</span>';
                    }else{
                        return d.statename;
                    }
                }}
                ,{field:'yifufee',title:'累计已收票金额(元)B',totalRow: true,templet: function(d){
                        return parseFormatNum(d.yifufee);
                    }}
                ,{field:'daifufee',title:'待收票金额(元)A-B',totalRow: true,templet: function(d){
                        return parseFormatNum(d.daifufee);
                    }}
                ,{field:'difee',title:'本次关联进项票金额',totalRow: true,templet: function(d){
                        return parseFormatNum(d.difee);
                    }}
                ,{field: 'enginname', title: '工程名称'}
                ,{field: 'enginnumber', title: '工程编号'}
                ,{field: 'gofuer', title: '工程负责人'}
                ,{field: 'flowuser', title: '申请人'}
                ,{field: 'created_at', title: '申请日期'}
            ]]
            , done: function (res) {
                soulTable.render(this);
            }
        });


        listTableSearch(form, table);
    });


    function auth_but_func_fan(buttitle){
        var checkStatus = layui.table.checkStatus('datalist').data;
        var idArr = [];
        var isshen = false;
        for(var i=0;i<checkStatus.length;i++){
            if(checkStatus[i].status == 0){
                isshen = true;
            }
            idArr.push(checkStatus[i].listid)
        }

        if(idArr.length < 1){
            facade.error(buttitle + "：请选择数据");return false;
        }
        if(isshen){
            facade.error(buttitle + "：请选择审批通过的数据");return false;
        }

        openPageEdit('fan.php?close=1&ids='+idArr.join(','), '770px', '490px');
    }


</script>
</body>
</html>
